package edu.ynu.se.xiecheng.achitectureclass.nongye.controller;

import edu.ynu.se.xiecheng.achitectureclass.nongye.dao.TemperatureDAO;
import edu.ynu.se.xiecheng.achitectureclass.nongye.entity.Temperature;
import edu.ynu.se.xiecheng.achitectureclass.nongye.service.TemperatureService;
import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "温度管理")
@RestController
@RequestMapping("/temperature")
public class TemperatureController extends LogicController<TemperatureService, TemperatureDAO, Temperature, Integer> {

    @Autowired
    public TemperatureController(TemperatureService temperatureService) {
        super(temperatureService);
    }

    @ApiOperation("根据ID获取温度信息")
    @GetMapping("/gettemperature")
    public Temperature getTemperatureById(@RequestParam Integer id) {
        return getService().GET(id);
    }

    @ApiOperation("获取所有温度信息")
    @GetMapping("/getAlltemperature")
    public List<Temperature> getAllTemperature() {
        return getService().getAll();
    }

    @ApiOperation("创建温度记录")
    @PostMapping("/posttemperature")
    public Temperature createTemperature(@RequestBody Temperature temperature) {
        return getService().POST(temperature);
    }

    @ApiOperation("更新温度记录")
    @PostMapping("/puttemperature")
    public Temperature updateTemperature(@RequestBody Temperature temperature) {
        return getService().PUT(temperature);
    }

    @ApiOperation("删除温度记录")
    @PostMapping("/deletetemperature")
    public void deleteTemperature(@RequestBody Temperature temperature) {
        getService().DELETE(temperature);
    }

    @ApiOperation("通过ID删除温度记录")
    @GetMapping("/deleteByIdtemperature")
    public void deleteTemperatureById(@RequestParam Integer id) {
        getService().DELETE(id);
    }
}
